﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Utils;
using RhotCMS.Models;
using Core.PageEntities;
using Infrastructure;
using Core.Logging;
using System.Threading;
using Core.Users;
using Core.AdditionalInterfaces;

namespace RhotCMS.Controllers
{
    public class PagesController : RhotCMSController, IAllowPreview
    {
        public PagesController(ILogger logger, ICurrentUserService user)
            : base(logger, user)
        {
            _pageManager = new PageManager();
        }

        public ActionResult Index()
        {          
            var group = ControllerContext.RouteData.Values["group"].With(x=>x.ToString().ToLower());
            var name = ControllerContext.RouteData.Values["name"].With(x=>x.ToString().ToLower());

            ViewBag.Group = group;
            ViewBag.Name = name;

            if (String.IsNullOrWhiteSpace(group))
                group = "root";
            if (String.IsNullOrWhiteSpace(name))
                name = "index";

            var page = _pageManager.GetSinglePageByGroupNameLang(group, name, UILangName);

            if(page==null)
                return View("NotFound");

            return View(page);
        }

    }
}
